import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

// 设置header. 设置header中的refresh达到页面自动刷新的效果.
@WebServlet("/refresh")
public class AutoRefreshServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 直接返回响应就好.
        resp.setHeader("refresh","2"); // 2s 刷新一次.
        // 返回一个时间戳 方便查看刷新的效果.
        resp.getWriter().write(System.currentTimeMillis()+ " ");
    }
}
